import { UserActives } from './userActive';
let _UserActives = UserActives;
/**
 * 拷贝下面两行到 mock/index.js中,即可支持客户端虚拟数据、免服务端连接
 * import UserActiveMock from './mk/mng/computed/day/userActiveMock';
 * UserActiveMock.bootstrap(mock);
 */
export default {
  /**
   * mock bootstrap
   */
  bootstrap(mock) {    
  
    //获取列表 模糊查询、根据关键字查询
    mock.onGet('/mk/mng/computed/day/userActive/listKey').reply(config => {
      let params = config.params;
      let mockUserActives = _UserActives.filter(userActive => {
      	if(params.id||params.id==''){ if( userActive.id.indexOf(params.id)>=0) return true;}
      	if(params.userCount||params.userCount==''){ if( userActive.userCount.indexOf(params.userCount)>=0) return true;}
      	if(params.countDate||params.countDate==''){ if( userActive.countDate.indexOf(params.countDate)>=0) return true;}
      	if(params.iosCount||params.iosCount==''){ if( userActive.iosCount.indexOf(params.iosCount)>=0) return true;}
      	if(params.andoridCount||params.andoridCount==''){ if( userActive.andoridCount.indexOf(params.andoridCount)>=0) return true;}
      	if(params.mobileCount||params.mobileCount==''){ if( userActive.mobileCount.indexOf(params.mobileCount)>=0) return true;}
      	if(params.wechatCount||params.wechatCount==''){ if( userActive.wechatCount.indexOf(params.wechatCount)>=0) return true;}
      	if(params.pcCount||params.pcCount==''){ if( userActive.pcCount.indexOf(params.pcCount)>=0) return true;}
      	if(params.computedStatus||params.computedStatus==''){ if( userActive.computedStatus.indexOf(params.computedStatus)>=0) return true;}
      	if(params.startComputedDate||params.startComputedDate==''){ if( userActive.startComputedDate.indexOf(params.startComputedDate)>=0) return true;}
      	if(params.bizDate||params.bizDate==''){ if( userActive.bizDate.indexOf(params.bizDate)>=0) return true;}
      	if(params.userLoginCount||params.userLoginCount==''){ if( userActive.userLoginCount.indexOf(params.userLoginCount)>=0) return true;}
        return false;
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            data: mockUserActives
          }]);
        }, 1000);
      });
    });
    
    

    //获取列表（分页/不分页）
    mock.onGet('/mk/mng/computed/day/userActive/list').reply(config => {
      let params = config.params;
      let mockUserActives = _UserActives.filter(userActive => {
      	var isTrue=false;
      	if(params.id||params.id==''){if(userActive.id.indexOf(params.id)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.userCount||params.userCount==''){if(userActive.userCount.indexOf(params.userCount)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.countDate||params.countDate==''){if(userActive.countDate.indexOf(params.countDate)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.iosCount||params.iosCount==''){if(userActive.iosCount.indexOf(params.iosCount)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.andoridCount||params.andoridCount==''){if(userActive.andoridCount.indexOf(params.andoridCount)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.mobileCount||params.mobileCount==''){if(userActive.mobileCount.indexOf(params.mobileCount)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.wechatCount||params.wechatCount==''){if(userActive.wechatCount.indexOf(params.wechatCount)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.pcCount||params.pcCount==''){if(userActive.pcCount.indexOf(params.pcCount)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.computedStatus||params.computedStatus==''){if(userActive.computedStatus.indexOf(params.computedStatus)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.startComputedDate||params.startComputedDate==''){if(userActive.startComputedDate.indexOf(params.startComputedDate)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.bizDate||params.bizDate==''){if(userActive.bizDate.indexOf(params.bizDate)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.userLoginCount||params.userLoginCount==''){if(userActive.userLoginCount.indexOf(params.userLoginCount)>=0){isTrue=true;}else{isTrue=false;}}
      	return isTrue;
	  });
      if(!config.params.currentPage){ 
	      return new Promise((resolve, reject) => {
	        setTimeout(() => {
	          resolve([200, {
	            data: mockUserActives
	          }]);
	        }, 1000);
	      });
      }
    
      let {pageSize,currentPage, total} = config.params;
      total = mockUserActives.length;
      mockUserActives = mockUserActives.filter((userActive, index) => index < pageSize * currentPage && index >= pageSize * (currentPage - 1));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            pageInfo: {
            	total:total
            },
            data: mockUserActives,
            tips:{
            	isOk:true,
            	msg:'查询成功'
            }
          }]);
        }, 1000);
      });
    });

    //删除
    mock.onPost('/mk/mng/computed/day/userActive/del').reply(config => {
      var params = JSON.parse( config.data );
      let {  id  } = params;
      _UserActives = _UserActives.filter(userActive => userActive.id !== id);
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //批量删除
    mock.onPost('/mk/mng/computed/day/userActive/batchDel').reply(config => {
      var params = JSON.parse( config.data );
      _UserActives = _UserActives.filter(userActive => !params.includes(userActive.id));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
           tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //编辑
    mock.onPost('/mk/mng/computed/day/userActive/edit').reply(config => {
      var params = JSON.parse( config.data );
      let { id,userCount,countDate,iosCount,andoridCount,mobileCount,wechatCount,pcCount,computedStatus,startComputedDate,bizDate,userLoginCount } = params;
      _UserActives.some(userActive => {
        if (userActive.id === id) {
			userActive.id = id;
			userActive.userCount = userCount;
			userActive.countDate = countDate;
			userActive.iosCount = iosCount;
			userActive.andoridCount = andoridCount;
			userActive.mobileCount = mobileCount;
			userActive.wechatCount = wechatCount;
			userActive.pcCount = pcCount;
			userActive.computedStatus = computedStatus;
			userActive.startComputedDate = startComputedDate;
			userActive.bizDate = bizDate;
			userActive.userLoginCount = userLoginCount
          return true;
        }
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'编辑成功'
            }
          }]);
        }, 500);
      });
    });

    //新增
    mock.onPost('/mk/mng/computed/day/userActive/add').reply(config => {
      var params = JSON.parse( config.data );
      let { id,userCount,countDate,iosCount,andoridCount,mobileCount,wechatCount,pcCount,computedStatus,startComputedDate,bizDate,userLoginCount } = params;
      _UserActives.push({
		id:id,
		userCount:userCount,
		countDate:countDate,
		iosCount:iosCount,
		andoridCount:andoridCount,
		mobileCount:mobileCount,
		wechatCount:wechatCount,
		pcCount:pcCount,
		computedStatus:computedStatus,
		startComputedDate:startComputedDate,
		bizDate:bizDate,
		userLoginCount:userLoginCount
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'新增成功'
            }
          }]);
        }, 500);
      });
    });

  }
};